package icu.cocoon.work.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.core.metadata.OrderItem;
import com.baomidou.mybatisplus.core.toolkit.StringUtils;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import icu.cocoon.dao.base.BaseController;
import icu.cocoon.dao.base.Resp;
import icu.cocoon.system.entity.User;
import icu.cocoon.system.service.SecurityService;
import icu.cocoon.work.entity.TestReportItem;
import icu.cocoon.work.service.TestReportItemService;
import io.jsonwebtoken.lang.Assert;
import java.util.Map;
import javax.annotation.Resource;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/work/testReportItem")
public class TestReportItemController extends BaseController<TestReportItem, TestReportItemService> {

  @Resource
  private SecurityService securityService;

  @Override
  public Resp<TestReportItem> create(@RequestBody TestReportItem model) {
    User user = securityService.getCurrentUser();
    Assert.notNull(user, "无法获取当前用户");
    model.setCreateUserId(user.getId());
    return super.create(model);
  }


  @Override
  protected IPage<TestReportItem> getPage(Map<String, String> params) {
    long page = 0;
    long size = 10;
    if (StringUtils.isNotBlank(params.get("page"))) {
      page = Integer.parseInt(params.get("page"));
      params.remove("page");
    }
    if (StringUtils.isNotBlank(params.get("size"))) {
      size = Integer.parseInt(params.get("size"));
      params.remove("size");
    }
    return new Page<TestReportItem>(page, size).addOrder(OrderItem.asc("id"));

  }
}


